package org.azj.sqlStatementGenerator;

import org.azj.dbOperatorComponent.ColumnProperty;
import org.azj.fieldTypeConverter.ConverterFactory;
import org.azj.logHelper.LOG;

// represent the real statement like "Col1 > 3" 
public class ConcreateStatement extends Statement{
	private ColumnProperty columnProperty;
	private OPERATOR operator;
	private Object value;
	
	public ConcreateStatement(
			ColumnProperty columnProperty, OPERATOR operator, Object value)
	{
		this.columnProperty = columnProperty;
		this.operator = operator;
		this.value = value;
	}
	
	
	@Override
	public void addStatement(Statement statement)  throws SqlStatementBuildingException{
		throw new SqlStatementBuildingAppendException(
				statement.getStatements(), this.getStatements());
	}

	@Override
	public void removeStatement(Statement statement)  throws SqlStatementBuildingException{
		throw new SqlStatementBuildingRemoveException(
				statement.getStatements(), this.getStatements());
	}

	@Override
	public String getStatements() throws SqlStatementBuildingException {
		String colNameString = columnProperty.getColumnFullName();
		String opNameString = operator.toString();
		String valueString = "";
		try {
			valueString = ConverterFactory.GetConverterByFieldType(
					columnProperty.getDataTypeName()).Convert(value, colNameString);
		} catch (Exception e) {
			LOG.WriteLog("数据转换过程中出现问题 : 错误的语句是[" 
					+ colNameString + opNameString + value 
					+ "]，列的属性是[" + columnProperty.getDataTypeName() + "]" );
			throw new SqlStatementBuildingTypeUnmatchedException(
					colNameString + opNameString + value, columnProperty.getDataTypeName());
		}
				
		return colNameString + opNameString + valueString;
	}
}
